package com.ruiysoft.service.mdse.impl;


import com.ruiysoft.conf.mq.MdseMqConfig;
import com.ruiysoft.service.mdse.IMerchandiseStock;
import com.ruiysoft.service.mdse.bean.MerchandiseStoceEnvelope;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MerchandiseStockImpl implements IMerchandiseStock,RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback {

	@Resource
	private RabbitTemplate rabbitTemplate;

	@Override
	public void confirm(CorrelationData correlationData, boolean ack, String cause) {
			System.out.println("消息发送成功:"+correlationData);
			}

	@Override
	public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
			System.out.println("消息发送失败:" + new String(message.getBody()));
	}


	@Override
	public String handler(Long skuId, Integer stockNum) {
		MerchandiseStoceEnvelope env = new MerchandiseStoceEnvelope();
		env.setSkuId(skuId);
		env.setNum(stockNum);
		return handler(env);
	}
	@Override
	public String handler(MerchandiseStoceEnvelope env){
		rabbitTemplate.convertAndSend(MdseMqConfig.MDSE_QUANTITY_EXCHANGE, MdseMqConfig.MDSE_QUANTITY_BIND_KEY,env);
		return "abc";
	}
}
